import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

//解决重复点击左侧菜单的报错问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}


export const asyncRoutes = [
  {
    path: '/',
    name: 'layout',
    redirect: '/home',
    component:  () => import('@/layout/index.vue'),
    meta: {
      title: "首页",
      icon: 'el-icon-s-custom',
    },
    children: [
      {
        name: 'home',
        path: '/home',
        component:  () => import('@/views/home.vue'),
        meta: {
          title: "首页",
        },
      },
    ]
  },
  {
    path: '/company',
    name: 'layout',
    redirect: '/home',
    component:  () => import('@/layout/index.vue'),
    meta: {
      title: "企业管理",
      icon: 'el-icon-s-custom',
    },
    children: [
      {
        name: 'user',
        path: '/user',
        component:  () => import('@/views/user/index.vue'),
        meta: {
          title: "企业账号",
        },
      },
      // {
      //   name: 'recharge',
      //   path: '/recharge',
      //   component:  () => import('@/views/recharge/index.vue'), meta: {
      //     title: "充值记录",
      //   },
      // },
      {
        name: 'product',
        path: '/product',
        component:  () => import('@/views/product/index.vue'), meta: {
          title: "产品列表",
        },
      },
    ]
  },
  {
    path: '/chat',
    name: 'layout',
    redirect: '/home',
    component:  () => import('@/layout/index.vue'),
    meta: {
      title: "Chat管理",
      icon: 'el-icon-s-custom',
    },
    children: [
      // {
      //   name: 'consume',
      //   path: '/consume',
      //   component:  () => import('@/views/consume/index.vue'),
      //   meta: {
      //     title: "消费记录",
      //   },
      // },
      {
        name: 'message',
        path: '/message',
        component:  () => import('@/views/message/index.vue'),
        meta: {
          title: "聊天记录",
        },
      },
    ]
  },
  {
    path: '/product',
    name: 'layout',
    redirect: '/home',
    component:  () => import('@/layout/index.vue'),
    meta: {
      title: "商品推荐",
      icon: 'el-icon-s-custom',
    },
    children: [
      {
        name: 'messageProduct',
        path: '/messageProduct',
        component:  () => import('@/views/messageProduct/index.vue'),
        meta: {
          title: "商品推荐记录",
        },
      },
      // {
      //   name: 'messageOpenProduct',
      //   path: '/messageOpenProduct',
      //   component:  () => import('@/views/messageOpenProduct/index.vue'),
      //   meta: {
      //     title: "商品打开记录",
      //   },
      // },
    ]
  },
  {
    path: '/admin',
    name: 'layout',
    redirect: '/home',
    component:  () => import('@/layout/index.vue'),
    meta: {
      title: "员工管理",
      icon: 'el-icon-s-custom',
    },
    children: [
      {
        name: 'admin',
        path: '/admin',
        component:  () => import('@/views/admin/index.vue'),
        meta: {
          title: "员工管理",
        },
      },
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/Login'),
    meta: {
      title: "欢迎登录",
    },
    hidden: true //导航菜单忽略选项
  },
]


const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes: asyncRoutes
})

export default router
